<?php
class orderController extends RPHP_Controller
{

    //权限前缀
    protected $_pvprefix = "order";
    //列表
    public function olist()
    {

        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if ($_GET['gkwd'] != "") {
                $keyword = addslashes(trim($_GET['gkwd']));
                if ($keyword != '') {
                    $para['gkwd'] = $keyword;
                }

            }

            if ($_GET['recode'] != "") {
                $recode= addslashes(trim($_GET['recode']));
                if ($recode != '') {
                    $para['recode'] = $recode;
                }

            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            if (isset($_GET['order_status']) && $_GET['order_status'] != "") {
                $order_status = intval($_GET['order_status']);
                if ($order_status >= 0) {
                    $para['order_status'] = $order_status;
                }

            }
            if (isset($_GET['sell_type']) && $_GET['sell_type'] != "") {

                $para['sell_type'] = intval($_GET['sell_type']);

            }

            /*  if (isset($_GET['bid_type']) && $_GET['bid_type'] != "") {

            $para['bid_type'] = intval($_GET['bid_type']);

            } */
            if (isset($_GET['shipping_id']) && $_GET['shipping_id'] != "") {
                $shipping_id = intval($_GET['shipping_id']);
                if ($shipping_id >= 0) {
                    $para['shipping_id'] = $shipping_id;
                }

            }
            if (isset($_GET['shipping_name']) && $_GET['shipping_name'] != "") {
                $shipping_name = intval($_GET['shipping_name']);
                if ($shipping_name >= 0) {
                    $para['shipping_name'] = $shipping_name;
                }

            }

            if (isset($_GET['shipping_status']) && $_GET['shipping_status'] != "") {
                $shipping_status = intval($_GET['shipping_status']);
                if ($shipping_status >= 0) {
                    $para['shipping_status'] = $shipping_status;
                }

            }

            if (isset($_GET['pay_status']) && $_GET['pay_status'] != "") {
                $pay_status = intval($_GET['pay_status']);
                if ($pay_status >= 0) {
                    $para['pay_status'] = $pay_status;
                }

            }

            if (isset($_GET['province_id']) && $_GET['province_id'] != "") {
                $province_id = intval($_GET['province_id']);
                if ($province_id >= 0) {
                    $para['province_id'] = $province_id;
                    $this->view->city_list = $model->getRegionAjax($province_id);
                }



            }

            if (isset($_GET['city_id']) && $_GET['city_id'] != "") {
                $city_id = intval($_GET['city_id']);
                if ($city_id >= 0) {
                    $para['city_id'] = $city_id;
                    $this->view->county_list = $model->getRegionAjax($city_id);
                }

            }

            if (isset($_GET['county_id']) && $_GET['county_id'] != "") {
                $county_id = intval($_GET['county_id']);
                if ($county_id >= 0) {
                    $para['county_id'] = $county_id;
                }

            }

            if (isset($_GET['tui']) && $_GET['tui'] == "yes") {
                $para['tui'] = "yes";
            }

            if (isset($_GET['uid']) && $_GET['uid'] != "") {
                $uid = intval($_GET['uid']);
                if ($uid >= 0) {
                    $para['uid'] = $uid;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }


            $province = $model->getRegionAjax();

          /*  $data['city_list'] = $model->getRegionAjax(197);

            $data['county_list'] = $model->getRegionAjax(198);*/


            $data = $model->getOrder($para, $page);

            if ($data['data']) {
                foreach ($data['data'] as $r) {
                    if ($r['uid'] > 0) {
                        $uids[] = $r['uid'];
                    }

                }
                if ($data['data']) {
                    foreach ($data['data'] as $r) {
                        if ($r['headimgurl'] > 0) {
                            $docid[] = $r['headimgurl'];
                        }

                    }
                    if ($docid) {
                        $docs = $this->getDocs($docid);
                    }

                }

                $data['user'] = $model->getMemberInfo($uids);
            }

            //获取页码
            if ($data['maxpage'] > 1) {
                $data['spage'] = $model->fun->spage($data['page'], $data['maxpage']);
            }

            //查看权限
            $this->view->pv['view'] = $model->checkPriv($this->_pvprefix . "_vw", false);
            //导出权限
            $this->view->pv['export'] = $model->checkPriv($this->_pvprefix . "_ex", false);
            //导入权限
            $this->view->pv['import'] = $model->checkPriv($this->_pvprefix . "_im", false);
            //打印权限
            $this->view->pv['print'] = $model->checkPriv($this->_pvprefix . "_op", false);
            $this->view->data        = $data;
            $this->view->province        = $province;

            $this->display();

        }

    }

    //统计
    public function order_money_count()
    {

        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['recode'] != "") {
                $recode= addslashes(trim($_GET['recode']));
                if ($recode != '') {
                    $para['recode'] = $recode;
                }

            }
            if ($_GET['gkwd'] != "") {
                $keyword = addslashes(trim($_GET['gkwd']));
                if ($keyword != '') {
                    $para['gkwd'] = $keyword;
                }

            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            if (isset($_GET['order_status']) && $_GET['order_status'] != "") {
                $order_status = intval($_GET['order_status']);
                if ($order_status >= 0) {
                    $para['order_status'] = $order_status;
                }

            }
            if (isset($_GET['sell_type']) && $_GET['sell_type'] != "") {

                $para['sell_type'] = intval($_GET['sell_type']);

            }

            /*  if (isset($_GET['bid_type']) && $_GET['bid_type'] != "") {

            $para['bid_type'] = intval($_GET['bid_type']);

            } */
            if (isset($_GET['shipping_id']) && $_GET['shipping_id'] != "") {
                $shipping_id = intval($_GET['shipping_id']);
                if ($shipping_id >= 0) {
                    $para['shipping_id'] = $shipping_id;
                }

            }
            if (isset($_GET['shipping_name']) && $_GET['shipping_name'] != "") {
                $shipping_name = intval($_GET['shipping_name']);
                if ($shipping_name >= 0) {
                    $para['shipping_name'] = $shipping_name;
                }

            }

            if (isset($_GET['shipping_status']) && $_GET['shipping_status'] != "") {
                $shipping_status = intval($_GET['shipping_status']);
                if ($shipping_status >= 0) {
                    $para['shipping_status'] = $shipping_status;
                }

            }

            if (isset($_GET['pay_status']) && $_GET['pay_status'] != "") {
                $pay_status = intval($_GET['pay_status']);
                if ($pay_status >= 0) {
                    $para['pay_status'] = $pay_status;
                }

            }

            if (isset($_GET['province_id']) && $_GET['province_id'] != "") {
                $province_id = intval($_GET['province_id']);
                if ($province_id >= 0) {
                    $para['province_id'] = $province_id;

                }



            }

            if (isset($_GET['city_id']) && $_GET['city_id'] != "") {
                $city_id = intval($_GET['city_id']);
                if ($city_id >= 0) {
                    $para['city_id'] = $city_id;

                }

            }

            if (isset($_GET['county_id']) && $_GET['county_id'] != "") {
                $county_id = intval($_GET['county_id']);
                if ($county_id >= 0) {
                    $para['county_id'] = $county_id;
                }

            }

            if (isset($_GET['tui']) && $_GET['tui'] == "yes") {
                $para['tui'] = "yes";
            }

            if (isset($_GET['uid']) && $_GET['uid'] != "") {
                $uid = intval($_GET['uid']);
                if ($uid >= 0) {
                    $para['uid'] = $uid;
                }

            }
            //print_r($_GET);die;
            $data = $model->getOrderMoneyCount($para);
            echo json_encode($data);

        }

    }

    //竞拍记录
    public function bidhistory()
    {
        $priv  = array($this->_pvprefix . "_ls");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $orderid          = intval($_GET['order_id']);
            $data             = $model->getOrderBidRecord($orderid);
            $this->view->auth = $auth;
            $this->view->data = $data;
            $this->display();
        }
    }
    //打印页面
    public function orderprint()
    {
        $priv  = array($this->_pvprefix . "_op");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $order_id = intval($_GET['order_id']);
            $data     = $model->getOrderDetail($order_id);
            //print_r($data);die;
            $this->view->data = $data;
            $this->view->auth = $auth;
            $this->display();
        }

    }

    //AJAX操作
    public function ajax()
    {

        $priv = array($this->_pvprefix . "_ls");

        $model        = $this->model;
        $auth         = $model->checkPriv($priv);
        $data['code'] = 900;
        if ($auth) {
            if ($_POST['act'] == 'checkpay') {
                $data = $model->getCheckPayResult($_POST['order_id']);
            } elseif ($_POST['act'] == 'checkupgradepay') {
                $data = $model->getCheckUpgradePayResult($_POST['payid']);
            } elseif ($_POST['act'] == 'shipping_status') {

                $data = $model->saveOrderShippingStatus($_POST);
            } elseif ($_POST['act'] == 'add') {

                $data = $model->saveExpress($_POST);
            } elseif ($_POST['act'] == 'edit') {

                $data = $model->saveExpress($_POST, $_POST['id']);
            } elseif ($_POST['act'] == 'province') {
                //修改订单地址
                $data = $model->updateRegion($_POST);
            } elseif ($_POST['act'] == 'returnedit') {
                //修改申请退货
                $data = $model->getReturnEdit($_POST);
            } elseif ($_POST['act'] == 'reimburseedit') {
                //修改申请退款
                $data = $model->getReimburseEdit($_POST);
            } elseif ($_POST['act'] == 'ajax_purchase_price') {
                //修改进货价
                $data = $model->savePurchasePrice($_POST);
            } elseif ($_POST['act'] == 'ajax_supplierid') {
                //修改供应商
                $data = $model->saveSupplierid($_POST);
            } elseif ($_POST['act'] == 'receive_order') {
                //确认收货
                //print_r($_POST);
                $data = $model->saveSeceiveOrder($_POST);
            } elseif ($_POST['act'] == 'getCiys') {
                //地区变动
                //print_r($_POST);
                $data = $model->saveAddrInfo($_POST);
            }

        }
        echo json_encode($data);

    }

    //订单操作
    public function save()
    {

        $code = 900;

        $priv = array($this->_pvprefix . "_vw");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $this->view->auth = $auth;

            //设为未付款
            if ($_POST['act'] == "unpay" && $model->checkPriv($this->_pvprefix . "_py", false)) {
                $this->view->success = "已将订单设为未付款";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'unpay');
            }
            //设为已付款
            elseif ($_POST['act'] == "payed" && $model->checkPriv($this->_pvprefix . "_py", false)) {
                $this->view->success = "已将订单设为已付款";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'payed');
            }
            //设为已发货
            elseif ($_POST['act'] == "shipping" && $model->checkPriv($this->_pvprefix . "_sh", false)) {
                $this->view->success = "已将订单设为已发货";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'shipping', $_POST);
            }
            //设为已收货
            elseif ($_POST['act'] == "received" && $model->checkPriv($this->_pvprefix . "_sh", false)) {
                $this->view->success = "已将订单设为已收货";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'received');
            }
            //设为交易完成
            elseif ($_POST['act'] == "done" && $model->checkPriv($this->_pvprefix . "_ed", false)) {
                $this->view->success = "已将订单设为交易完成";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'done');
            }
            //设为取消订单
            elseif ($_POST['act'] == "cancel" && $model->checkPriv($this->_pvprefix . "_ed", false)) {
                $this->view->success = "已将订单设为取消订单";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'cancel');
            }
            //设为已完成退款
            elseif ($_POST['act'] == "refund" && $model->checkPriv($this->_pvprefix . "_rese", false)) {
                $this->view->success = "已将订单设为退款成功";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
           
                $code = $model->saveOrderStatus($_POST['order_id'], 'refund');
            }
            //设为退款驳回
            elseif ($_POST['act'] == "refund_turn" && $model->checkPriv($this->_pvprefix . "_rese", false)) {
                $this->view->success = "退款驳回成功";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'refund_turn');
            }
            //设为已完成退款与退货
            elseif ($_POST['act'] == "rcvgoods" && $model->checkPriv($this->_pvprefix . "_ed", false)) {
                $this->view->success = "已将订单设为退款成功并收到退货";
                $this->view->link    = array(
                    array('name' => '返回订单详情', 'url' => '/order/detail?order_id=' . $_POST['order_id']),
                    array('name' => '返回订单列表', 'url' => '/order/olist'),
                );
                $code = $model->saveOrderStatus($_POST['order_id'], 'rcvgoods');
            }

            $this->view->code = $code;
            $this->displaydo();

        }
    }

    public function order_goods_detail()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $order_id = intval($_GET['order_id']);
            if ($order_id > 0) {
                $data = $model->getSingleOrder($order_id);
            }
            if ($data) {
                $this->view->auth = $auth;
                $this->view->data = $data;
                $this->display();

            }
        }

    }

    //查看订单
    public function detail()
    {
        $priv = array($this->_pvprefix . "_vw");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $order_id = intval($_GET['order_id']);
            if ($order_id > 0) {
                $data = $model->getSingleOrder($order_id);
            }
            if ($data) {
                $this->view->supplier = $model->getSuppliers();

                $this->view->province = $model->getRegionAjax();

                if ($data['province_id'] > 0) {
                    $data['city_list'] = $model->getRegionAjax($data['province_id']);
                }

                if ($data['city_id'] > 0) {
                    $data['county_list'] = $model->getRegionAjax($data['city_id']);
                }

                $this->view->auth = $auth;

                $this->view->logs = $model->getOrderLog($data['order_id']);

                $this->view->data = $data;
                //收货人修改
                $this->view->pv['consignee'] = $model->checkPriv($this->_pvprefix . "_exit", false);

                $this->display();

            }
        }

    }

    public function shipping_edit()
    {

        $priv = array($this->_pvprefix . "_sp");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            if ($_POST['act'] == "edit") {
                $data = $model->saveShippingStatus($_POST);
                echo json_encode($data);
            } else {
                $exlist             = $model->getExpressCompany();
                $rec_id             = intval($_GET['rec_id']);
                $data               = $model->getShippingInfo($rec_id);
                $this->view->data   = $data;
                $this->view->auth   = $auth;
                $this->view->exlist = $exlist;
                $this->display();

            }

        }
    }

    //申请退货
    public function return_edit()
    {
        $priv = array($this->_pvprefix . "_rern");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            if ($_GET['rec_id']) {
                $para['rec_id'] = intval($_GET['rec_id']);
            }
            if ($_GET['order_id']) {
                $para['order_id'] = intval($_GET['order_id']);
            }
            //查询订单单个商品
            $this->view->data = $model->getOrderOne($para['rec_id']);
            $this->view->para = $para;

            $this->view->auth = $auth;
            $this->display();
        }
    }

    //申请退款
    public function reimburse_edit()
    {
        $priv = array($this->_pvprefix . "_rese");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            if ($_GET['rec_id']) {
                $para['rec_id'] = intval($_GET['rec_id']);
            }
            if ($_GET['order_id']) {
                $para['order_id'] = intval($_GET['order_id']);
            }
            //查询订单单个商品
            $this->view->data = $model->getOrderOne($para['rec_id']);
            $this->view->para = $para;

            $this->view->auth = $auth;
            $this->display();
        }
    }

    //导出未发货订单信息
    public function export()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth     = $auth;
            $type                 = empty($_GET['type']) ? 0 : $_GET['type'];
            $this->view->type     = $type;
            $this->view->supplier = $model->getSuppliers();
            //print_r($this->view->supplier);die;
            $this->display();
        }
    }

    /*导入物流信息*/

    //导入界面
    public function import()
    {
        $priv = array($this->_pvprefix . "_im");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->display();
        }
    }

    public function exlist()
    {
        $priv = array($this->_pvprefix . "_ec");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            $data = $model->getExpressList($para, $page);

            //获取页码
            if ($data['maxpage'] > 1) {
                $data['spage'] = $model->fun->spage($data['page'], $data['maxpage']);
            }

            $this->view->data = $data;
            $this->display();

        }

    }

    //快递添加
    public function exadd()
    {

        $priv = array($this->_pvprefix . "_ec");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->display();
        }
    }

    //快递添加
    public function exedit()
    {

        $priv = array($this->_pvprefix . "_ec");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $id = intval($_GET['id']);
            if ($id > 0) {
                $data = $model->getExpress($id);
            }
            if ($data) {

                $this->view->auth = $auth;
                $this->view->data = $data;
                $this->display();
            }
        }
    }

    //物流执行导入
    public function importBatch()
    {
        $priv = array($this->_pvprefix . "_im");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $code             = 900;

            if ($_FILES['excelFile']['size'] > 0 && $_FILES['excelFile']['tmp_name'] != "") {
                $fi        = new finfo(FILEINFO_MIME_TYPE);
                $mime_type = $fi->file($_FILES['excelFile']['tmp_name']);
                $mime      = array(
                    2003 => array("application/vnd.ms-office", "application/msword", "application/vnd.ms-excel"),
                    2007 => array("application/zip"),
                );

                $format = explode(".", $file['name']);

                if ($format[count($format) - 1] == "xlsx") {
                    $ver = 2007;
                } elseif (in_array($mime_type, $mime[2003])) {
                    $ver = 2003;
                } elseif (in_array($mime_type, $mime[2007])) {
                    $ver = 2007;
                } else {
                    $ver = 2003;
                }

                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                RPHP::loadClass("PHPExcel_IOFactory", "extend/PHPExcel/Classes");
                RPHP::loadClass("PHPExcel_Reader_Excel5", "extend/PHPExcel/Classes");

                if ($ver == 2007) {
                    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
                } else {
                    $objReader = PHPExcel_IOFactory::createReader('Excel5');
                }

                $objPHPExcel = $objReader->load($_FILES['excelFile']['tmp_name']);
                // print_r($objPHPExcel);
                $sheet         = $objPHPExcel->getSheet(0);
                $objWorksheet  = $objPHPExcel->getActiveSheet();
                $highestRow    = $objWorksheet->getHighestRow(); //取得总行数
                $highestColumn = $objWorksheet->getHighestColumn(); //取得总列数

                //echo $highestRow;

                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //总列数
                $headtitle          = array();

                if ($highestRow >= 4) {
                    // 组合数据
                    for ($row = 4; $row <= $highestRow; $row++) {
                        for ($col = 0; $col < $highestColumnIndex; $col++) {
                            $tmp              = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                            $data[$row][$col] = trim($tmp);
                        }
                    }
                }
                ///print_r($data);die;
                if ($data) {
                    $code = $model->saveImport($data);
                } else {
                    $code = 404;
                }
            }

            @unlink($_FILES['excelFile']['tmp_name']);

            $this->view->success = "导入物流信息成功";
            $this->view->link    = array(
                array('name' => '返回继续导入', 'url' => '/order/import'),
                array('name' => '返回订单列表', 'url' => '/order/olist'),
            );

            $this->view->code = $code;
            $this->displaydo();

        }
    }

    //导出订单
    public function exports()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $order_id         = intval($_GET['order_id']);
            if ($order_id > 0) {
                $data = $model->getSingleOrder($order_id);
            }

            if ($data) {
                $orderData = array();
                $num       = 0;
                if ($data['region']) {
                    ksort($data['region']);
                    $data['address'] = implode("", $data['region']) . $data['address'];
                }
                foreach ($data['goods'] as $v) {
                    $num   = $num + 1;
                    $total = number_format($v['goods_number'] * $v['goods_price'], 2, ".", "");
                    $time  = date("Y-m-d H:i:s", $data['add_time']);

                    $orderData[] = array(
                        'order_id'        => $data['order_id'],
                        'goods_amount'    => $data['goods_amount'],
                        'shipping_status' => $this->c['stat']['order']['shipping'][$data['shipping_status']],
                        'pay_status'      => $this->c['stat']['order']['pay'][$data['pay_status']],
                        'consignee'       => $data['consignee'],
                        'mobile'          => $data['mobile'],
                        'address'         => $data['address'],
                        'shipping_id'     => $data['shipping_id'],
                        'shipping_fee'    => $data['shipping_fee'],
                        'shipping_id'     => $data['shipping_id'],
                        'shipping_name'   => $data['shipping_name'],
                        'goods_name'      => $v['goods_name'],
                        'goods_sn'        => $v['goods_sn'],
                        'goods_price'     => $v['goods_price'],
                        'goods_number'    => $v['goods_number'],
                        'total'           => $total,
                        'add_time'        => $time,
                    );
                }
                if ($orderData) {
                    RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                    $excel       = new PHPExcel();
                    $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'); //,'N'   快递费用
                    $tableheader = array('订单号', '商品金额', '发货状态', '付款状态', '收货人', '联系电话', '收货地址', ' 快递单号', ' 快递费用', ' 快递公司', '商品名称', '商品编号', '商品单价', '购买数量', '单款合计', '创建时间');
                    $excel_H     = 2;
                    for ($i = 0; $i < count($tableheader); $i++) {
                        $excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
                    }
                    $i = $excel_H;
                    foreach ($orderData as $v) {
                        $excel->getActiveSheet()->setCellValue('K' . $i, $v['goods_name']);
                        $excel->getActiveSheet()->setCellValue('L' . $i, $v['goods_sn']);
                        $excel->getActiveSheet()->setCellValue('M' . $i, $v['goods_price']);
                        $excel->getActiveSheet()->setCellValue('N' . $i, $v['goods_number']);
                        $excel->getActiveSheet()->setCellValue('O' . $i, $v['total']);
                        $i = $i + 1;
                    }
                    //合并单元格
                    for ($k = $excel_H; $k <= $num + 1; $k++) {
                        $excel->getActiveSheet()->mergeCells('A' . $excel_H . ':A' . $k);
                        $excel->getActiveSheet()->mergeCells('B' . $excel_H . ':B' . $k);
                        $excel->getActiveSheet()->mergeCells('C' . $excel_H . ':C' . $k);
                        $excel->getActiveSheet()->mergeCells('D' . $excel_H . ':D' . $k);
                        $excel->getActiveSheet()->mergeCells('E' . $excel_H . ':E' . $k);
                        $excel->getActiveSheet()->mergeCells('F' . $excel_H . ':F' . $k);
                        $excel->getActiveSheet()->mergeCells('G' . $excel_H . ':G' . $k);
                        $excel->getActiveSheet()->mergeCells('H' . $excel_H . ':H' . $k);
                        $excel->getActiveSheet()->mergeCells('I' . $excel_H . ':I' . $k);
                        $excel->getActiveSheet()->mergeCells('J' . $excel_H . ':J' . $k);
                        $excel->getActiveSheet()->mergeCells('P' . $excel_H . ':P' . $k);
                    }
                    foreach ($orderData as $v) {
                        $excel->getActiveSheet()->setCellValue('A' . ($excel_H), $v['order_id']);
                        $excel->getActiveSheet()->setCellValue('B' . ($excel_H), $v['goods_amount']);
                        $excel->getActiveSheet()->setCellValue('C' . ($excel_H), $v['shipping_status']);
                        $excel->getActiveSheet()->setCellValue('D' . ($excel_H), $v['pay_status']);
                        $excel->getActiveSheet()->setCellValue('E' . ($excel_H), $v['consignee']);
                        $excel->getActiveSheet()->setCellValue('F' . ($excel_H), $v['mobile']);
                        $excel->getActiveSheet()->setCellValue('G' . ($excel_H), $v['address']);
                        $excel->getActiveSheet()->setCellValue('H' . ($excel_H), $v['shipping_id']);
                        $excel->getActiveSheet()->setCellValue('I' . ($excel_H), $v['shipping_fee']);
                        $excel->getActiveSheet()->setCellValue('J' . ($excel_H), $v['shipping_name']);
                        $excel->getActiveSheet()->setCellValue('P' . ($excel_H), $v['add_time']);
                    }
                    //创建Excel输入对象
                    $write = new PHPExcel_Writer_Excel5($excel);
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                    header("Content-Type:application/force-download");
                    header("Content-Type:application/vnd.ms-execl");
                    header("Content-Type:application/octet-stream");
                    header("Content-Type:application/download");
                    header('Content-Disposition:attachment;filename="订单' . $data['order_id'] . '.xls"');
                    header("Content-Transfer-Encoding:binary");
                    $write->save('php://output');

                }

            } else {
                RPHP_RR::nodata();
            }

        }

    }

    //订单导出
    public function exportBatch()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            if ($_GET['start_time'] != "" && $_GET['end_time'] != "") {

                $start_time     = strtotime($_GET['start_time'] . ":0");
                $end_time       = strtotime($_GET['end_time'] . ":0 -1 sec");
               // $warehouse_type = intval($_GET['warehouse_type']);
                $type           = intval($_GET['type']);
              //  $member_type    = intval($_GET['member_type']);
                $supplier_id    = intval($_GET['supplier_id']);
                $data = $model->getOrderDatas($start_time, $end_time, $supplier_id, $type);

                if ($data) {
                    $region = $model->getRegion();
                    foreach ($data as $k => $v) {
                        $orderData[] = array(
                            'rec_id'         => $v['rec_id'],
                            'order_id'       => $v['order_sn'],
                            'realname'       => $v['consignee'],
                            'mobile'         => $v['mobile'],
                            'address'        => $region[$v['province_id']] . $region[$v['city_id']] . $region[$v['county_id']] . $v['address'],
                            'goods_name'     => '[' . $v['goods_id'] . ']' . stripslashes($v['goods_name']),
                            'goods_sn'       => $v['goods_sn'],
                            'goods_price'    => $v['goods_price'],
                            'goods_number'   => $v['goods_number'],
                            'total'          => number_format($v['goods_number'] * $v['goods_price'], 2, ".", ""),
                            'add_time'       => date("Y-m-d H:i:s", $v['add_time']),
                            'uid'            => $v['uid'],
                            'idnum'          => $v['idnum'],
                            'warehouse_name' => $v['warehouse_name'],
                            'purchase_price' => $v['purchase_price'],
                            'shipping_id'    => $v['shipping_id'],
                            'shipping_name'  => $v['shipping_name'],
                            'supplier_name'  => $v['supplier_name'],
                            'gold_fee'       =>  $v['gold_fee'],
                            'coupon_fee'  => $v['coupon_fee'],
                            'discount_fee'  => $v['discount_fee'],
                            'name'  => $v['name'],
                            'recode'  => $v['recode'],
                        );
                    }

                }

                if ($orderData) {
                    RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                    $excel = new PHPExcel();

                    //设置excel属性基本信息
                    $excel->getProperties()->setCreator("LEHUO")
                        ->setLastModifiedBy("LEHUO")
                        ->setTitle("LEHUO")
                        ->setSubject("订单列表")
                        ->setDescription("")
                        ->setKeywords("订单列表")
                        ->setCategory("");
                    $excel->setActiveSheetIndex(0);
                    $excel->getActiveSheet()->setTitle("订单列表");
                    //填入表头主标题
                    $excel->getActiveSheet()->setCellValue('A1', '订单列表');
                    //填入表头副标题
                    $excel->getActiveSheet()->setCellValue('A2', '导出时间范围：' . date("Y-m-d H:i:s", $start_time) . '至' . date("Y-m-d H:i:s", $end_time));
                    //合并表头单元格
                    $excel->getActiveSheet()->mergeCells('A1:M1');
                    $excel->getActiveSheet()->mergeCells('A2:M2');

                    //设置表头行高
                    $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                    $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                    $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                    //设置表头字体
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                    $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                    $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V');
                    $tableheader = array('流水号码', '订单号', '收货人', '联系电话', '收货地址', '快递单号', '快递公司', '商品名称', '商品单价', '购买数量', '金额合计', '创建时间', 'UID', '身份证', '仓库类型', '进货价', '供应商', '金花抵扣', '优惠券抵扣', '代金券抵扣','邀请码','姓名');
                    $excel_H     = 4;
                    for ($i = 0; $i < count($tableheader); $i++) {
                        $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                    }

                    $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                    $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('D')->setWidth(16);
                    $excel->getActiveSheet()->getColumnDimension('E')->setWidth(80);
                    $excel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('M')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('N')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('S')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('T')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('U')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('V')->setWidth(20);
                    $total_money = 0;
                    foreach ($orderData as $num => $v) {
                        $line = $num + $excel_H;
                        $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                        $excel->getActiveSheet()->setCellValue('A' . $line, $v['rec_id']);
                        $excel->getActiveSheet()->setCellValue('B' . $line, ' ' . $v['order_id'] . " ");
                        $excel->getActiveSheet()->setCellValue('C' . $line, $v['realname']);
                        $excel->getActiveSheet()->setCellValue('D' . $line, $v['mobile'] . " ");
                        $excel->getActiveSheet()->setCellValue('E' . $line, $v['address']);
                        $excel->getActiveSheet()->setCellValue('F' . $line, $v['shipping_id'] . ' ');
                        $excel->getActiveSheet()->setCellValue('G' . $line, $v['shipping_name']);
                        $excel->getActiveSheet()->setCellValue('H' . $line, $v['goods_name']);
                        $excel->getActiveSheet()->setCellValue('I' . $line, $v['goods_price']);
                        $excel->getActiveSheet()->setCellValue('J' . $line, $v['goods_number']);
                        $excel->getActiveSheet()->setCellValue('K' . $line, $v['total']);
                        $excel->getActiveSheet()->setCellValue('L' . $line, $v['add_time']);
                        $excel->getActiveSheet()->setCellValue('M' . $line, $v['uid']);
                        $excel->getActiveSheet()->setCellValue('N' . $line, $v['idnum'] . " ");
                        $excel->getActiveSheet()->setCellValue('O' . $line, $v['warehouse_name']);
                        $excel->getActiveSheet()->setCellValue('P' . $line, $v['purchase_price']);
                        $excel->getActiveSheet()->setCellValue('Q' . $line, $v['supplier_name']);
                        $excel->getActiveSheet()->setCellValue('R' . $line, $v['gold_fee']." ");
                        $excel->getActiveSheet()->setCellValue('S' . $line, $v['discount_fee']." ");
                        $excel->getActiveSheet()->setCellValue('T' . $line, $v['coupon_fee']." ");
                        $excel->getActiveSheet()->setCellValue('U' . $line, $v['recode']." ");
                        $excel->getActiveSheet()->setCellValue('V' . $line, $v['name']." ");
                        $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                        $total_money += $v['total'];
                    }

                    // 合计金额
                    $new_line = $line + 1;
                    $excel->getActiveSheet()->mergeCells('A' . $new_line . ':J' . $new_line);
                    $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $new_line, '金额合计：');
                    $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                    $excel->getActiveSheet()->setCellValue('K' . $new_line, $total_money);

                    //设置单元格边框
                    $styleArray = array(
                        'borders' => array(
                            'allborders' => array(
                                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                                'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                                //'color' => array('argb' => 'FFFF0000'),
                            ),
                        ),
                    );
                    //设置单元格边框
                    $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                    //垂直居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    //水平居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                    //创建Excel输入对象
                    $write = new PHPExcel_Writer_Excel5($excel);
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                    header("Content-Type:application/force-download");
                    header("Content-Type:application/vnd.ms-execl");
                    header("Content-Type:application/octet-stream");
                    header("Content-Type:application/download");
                    header('Content-Disposition:attachment;filename="' . $supplier['name'] . '订单信息' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                    header("Content-Transfer-Encoding:binary");
                    $write->save('php://output');
                } else {
                    header("Content-type: text/html; charset=utf-8");
                    echo "没有要导出的数据";die;
                }
                // }

            }

        }
    }

    //订单全部导出
    public function exportAllBatch()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {


            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['recode'] != "") {
                $recode= addslashes(trim($_GET['recode']));
                if ($recode != '') {
                    $para['recode'] = $recode;
                }

            }
            if ($_GET['gkwd'] != "") {
                $keyword = addslashes(trim($_GET['gkwd']));
                if ($keyword != '') {
                    $para['gkwd'] = $keyword;
                }

            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            if (isset($_GET['order_status']) && $_GET['order_status'] != "") {
                $order_status = intval($_GET['order_status']);
                if ($order_status >= 0) {
                    $para['order_status'] = $order_status;
                }

            }
            if (isset($_GET['sell_type']) && $_GET['sell_type'] != "") {

                $para['sell_type'] = intval($_GET['sell_type']);

            }

            /*  if (isset($_GET['bid_type']) && $_GET['bid_type'] != "") {

            $para['bid_type'] = intval($_GET['bid_type']);

            } */
            if (isset($_GET['shipping_id']) && $_GET['shipping_id'] != "") {
                $shipping_id = intval($_GET['shipping_id']);
                if ($shipping_id >= 0) {
                    $para['shipping_id'] = $shipping_id;
                }

            }
            if (isset($_GET['shipping_name']) && $_GET['shipping_name'] != "") {
                $shipping_name = intval($_GET['shipping_name']);
                if ($shipping_name >= 0) {
                    $para['shipping_name'] = $shipping_name;
                }

            }

            if (isset($_GET['shipping_status']) && $_GET['shipping_status'] != "") {
                $shipping_status = intval($_GET['shipping_status']);
                if ($shipping_status >= 0) {
                    $para['shipping_status'] = $shipping_status;
                }

            }

            if (isset($_GET['pay_status']) && $_GET['pay_status'] != "") {
                $pay_status = intval($_GET['pay_status']);
                if ($pay_status >= 0) {
                    $para['pay_status'] = $pay_status;
                }

            }

            if (isset($_GET['province_id']) && $_GET['province_id'] != "") {
                $province_id = intval($_GET['province_id']);
                if ($province_id >= 0) {
                    $para['province_id'] = $province_id;

                }



            }

            if (isset($_GET['city_id']) && $_GET['city_id'] != "") {
                $city_id = intval($_GET['city_id']);
                if ($city_id >= 0) {
                    $para['city_id'] = $city_id;

                }

            }

            if (isset($_GET['county_id']) && $_GET['county_id'] != "") {
                $county_id = intval($_GET['county_id']);
                if ($county_id >= 0) {
                    $para['county_id'] = $county_id;
                }

            }

            if (isset($_GET['tui']) && $_GET['tui'] == "yes") {
                $para['tui'] = "yes";
            }

            if (isset($_GET['uid']) && $_GET['uid'] != "") {
                $uid = intval($_GET['uid']);
                if ($uid >= 0) {
                    $para['uid'] = $uid;
                }

            }


                $data = $model->getOrderAllDatas($para);

                if ($data) {
                    $region = $model->getRegion();
                    foreach ($data as $k => $v) {
                        $orderData[] = array(
                            'rec_id'         => $v['rec_id'],
                            'order_id'       => $v['order_sn'],
                            'realname'       => $v['consignee'],
                            'mobile'         => $v['mobile'],
                            'address'        => $region[$v['province_id']] . $region[$v['city_id']] . $region[$v['county_id']] . $v['address'],
                            'goods_name'     => '[' . $v['goods_id'] . ']' . stripslashes($v['goods_name']),
                            'goods_sn'       => $v['goods_sn'],
                            'goods_price'    => $v['goods_price'],
                            'goods_number'   => $v['goods_number'],
                            'total'          => number_format($v['goods_number'] * $v['goods_price'], 2, ".", ""),
                            'add_time'       => date("Y-m-d H:i:s", $v['add_time']),
                            'uid'            => $v['uid'],
                            'idnum'          => $v['idnum'],
                            'warehouse_name' => $v['warehouse_name'],
                            'purchase_price' => $v['purchase_price'],
                            'shipping_id'    => $v['shipping_id'],
                            'shipping_name'  => $v['shipping_name'],
                            'supplier_name'  => $v['supplier_name'],
                            'gold_fee'       =>  $v['gold_fee'],
                            'coupon_fee'  => $v['coupon_fee'],
                            'discount_fee'  => $v['discount_fee'],
                            'name'  => $v['name'],
                            'recode'  => $v['recode'],
                        );
                    }

                }

                if ($orderData) {
                    RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                    $excel = new PHPExcel();

                    //设置excel属性基本信息
                    $excel->getProperties()->setCreator("LEHUO")
                        ->setLastModifiedBy("LEHUO")
                        ->setTitle("LEHUO")
                        ->setSubject("订单列表")
                        ->setDescription("")
                        ->setKeywords("订单列表")
                        ->setCategory("");
                    $excel->setActiveSheetIndex(0);
                    $excel->getActiveSheet()->setTitle("订单列表");
                    //填入表头主标题
                    $excel->getActiveSheet()->setCellValue('A1', '订单列表');
                    //填入表头副标题
                    $excel->getActiveSheet()->setCellValue('A2', '导出时间：' .date("Y-m-d H:i:s", time()));
                    //合并表头单元格
                    $excel->getActiveSheet()->mergeCells('A1:M1');
                    $excel->getActiveSheet()->mergeCells('A2:M2');

                    //设置表头行高
                    $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                    $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                    $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                    //设置表头字体
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                    $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                    $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V');
                    $tableheader = array('流水号码', '订单号', '收货人', '联系电话', '收货地址', '快递单号', '快递公司', '商品名称', '商品单价', '购买数量', '金额合计', '创建时间', 'UID', '身份证', '仓库类型', '进货价', '供应商', '金花抵扣', '优惠券抵扣', '代金券抵扣','邀请码','姓名');
                    $excel_H     = 4;
                    for ($i = 0; $i < count($tableheader); $i++) {
                        $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                    }

                    $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                    $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('D')->setWidth(16);
                    $excel->getActiveSheet()->getColumnDimension('E')->setWidth(80);
                    $excel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('M')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('N')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('S')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('T')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('U')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('V')->setWidth(20);
                    $total_money = 0;
                    foreach ($orderData as $num => $v) {
                        $line = $num + $excel_H;
                        $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                        $excel->getActiveSheet()->setCellValue('A' . $line, $v['rec_id']);
                        $excel->getActiveSheet()->setCellValue('B' . $line, ' ' . $v['order_id'] . " ");
                        $excel->getActiveSheet()->setCellValue('C' . $line, $v['realname']);
                        $excel->getActiveSheet()->setCellValue('D' . $line, $v['mobile'] . " ");
                        $excel->getActiveSheet()->setCellValue('E' . $line, $v['address']);
                        $excel->getActiveSheet()->setCellValue('F' . $line, $v['shipping_id'] . ' ');
                        $excel->getActiveSheet()->setCellValue('G' . $line, $v['shipping_name']);
                        $excel->getActiveSheet()->setCellValue('H' . $line, $v['goods_name']);
                        $excel->getActiveSheet()->setCellValue('I' . $line, $v['goods_price']);
                        $excel->getActiveSheet()->setCellValue('J' . $line, $v['goods_number']);
                        $excel->getActiveSheet()->setCellValue('K' . $line, $v['total']);
                        $excel->getActiveSheet()->setCellValue('L' . $line, $v['add_time']);
                        $excel->getActiveSheet()->setCellValue('M' . $line, $v['uid']);
                        $excel->getActiveSheet()->setCellValue('N' . $line, $v['idnum'] . " ");
                        $excel->getActiveSheet()->setCellValue('O' . $line, $v['warehouse_name']);
                        $excel->getActiveSheet()->setCellValue('P' . $line, $v['purchase_price']);
                        $excel->getActiveSheet()->setCellValue('Q' . $line, $v['supplier_name']);
                        $excel->getActiveSheet()->setCellValue('R' . $line, $v['gold_fee']." ");
                        $excel->getActiveSheet()->setCellValue('S' . $line, $v['discount_fee']." ");
                        $excel->getActiveSheet()->setCellValue('T' . $line, $v['coupon_fee']." ");
                        $excel->getActiveSheet()->setCellValue('U' . $line, $v['recode']." ");
                        $excel->getActiveSheet()->setCellValue('V' . $line, $v['name']." ");
                        $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                        $total_money += $v['total'];
                    }

                    // 合计金额
                    $new_line = $line + 1;
                    $excel->getActiveSheet()->mergeCells('A' . $new_line . ':J' . $new_line);
                    $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $new_line, '金额合计：');
                    $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                    $excel->getActiveSheet()->setCellValue('K' . $new_line, $total_money);

                    //设置单元格边框
                    $styleArray = array(
                        'borders' => array(
                            'allborders' => array(
                                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                                'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                                //'color' => array('argb' => 'FFFF0000'),
                            ),
                        ),
                    );
                    //设置单元格边框
                    $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                    //垂直居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    //水平居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                    //创建Excel输入对象
                    $write = new PHPExcel_Writer_Excel5($excel);
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                    header("Content-Type:application/force-download");
                    header("Content-Type:application/vnd.ms-execl");
                    header("Content-Type:application/octet-stream");
                    header("Content-Type:application/download");
                    header('Content-Disposition:attachment;filename="订单信息' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                    header("Content-Transfer-Encoding:binary");
                    $write->save('php://output');
                } else {
                    header("Content-type: text/html; charset=utf-8");
                    echo "没有要导出的数据";die;
                }

        }
    }

    //批量导出订单
    public function exportBatchs()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $order_id = $_POST['order_ids'];
            if (!empty($order_id)) {
                $order_ids = explode(",", $order_id);
                $data      = $model->getOrderData($order_ids);
                if ($data) {
                    foreach ($data as $k => $v) {
                        foreach ($v['goods'] as $v1) {
                            $total                       = number_format($v1['goods_number'] * $v1['goods_price'], 2, ".", "");
                            $time                        = date("Y-m-d H:i:s", $v['add_time']);
                            $orderData[$v['order_id']][] = array(
                                'order_id'        => $v['order_sn'] . '(' . $v['order_id'] . ')',
                                'goods_amount'    => $v['goods_amount'],
                                'shipping_status' => $this->c['stat']['order']['shipping'][$v['shipping_status']],
                                'pay_status'      => $this->c['stat']['order']['pay'][$v['pay_status']],
                                'consignee'       => $v['consignee'],
                                'mobile'          => $v['mobile'],
                                'address'         => $v['address'],
                                'shipping_id'     => $v['shipping_id'],
                                'shipping_fee'    => $v['shipping_fee'],
                                'shipping_name'   => $v['shipping_name'],
                                'goods_name'      => $v1['goods_name'],
                                'goods_sn'        => $v1['goods_sn'],
                                'goods_price'     => $v1['goods_price'],
                                'goods_number'    => $v1['goods_number'],
                                'total'           => $total,
                                'add_time'        => $time,
                            );
                        }
                    }
                }
            } else {

                $start_time = strtotime($_GET['start_time']);
                $end_time   = strtotime($_GET['end_time']);

                if ($end_time) {
                    $end_time = $end_time + 24 * 3600;
                }

                $data = $model->getOrderData("", $start_time, $end_time);
                if ($data) {
                    foreach ($data as $k => $v) {
                        foreach ($v['goods'] as $v1) {
                            $total                       = number_format($v1['goods_number'] * $v1['goods_price'], 2, ".", "");
                            $time                        = date("Y-m-d H:i:s", $v['add_time']);
                            $orderData[$v['order_id']][] = array(
                                'order_id'        => $v['order_sn'] . '(' . $v['order_id'] . ')',
                                'goods_amount'    => $v['goods_amount'],
                                'shipping_status' => $this->c['stat']['order']['shipping'][$v['shipping_status']],
                                'pay_status'      => $this->c['stat']['order']['pay'][$v['pay_status']],
                                'consignee'       => $v['consignee'],
                                'mobile'          => $v['mobile'],
                                'address'         => $v['address'],
                                'shipping_id'     => $v['shipping_id'],
                                'shipping_fee'    => $v['shipping_fee'],
                                'shipping_name'   => $v['shipping_name'],
                                'goods_name'      => $v1['goods_name'],
                                'goods_sn'        => $v1['goods_sn'],
                                'goods_price'     => $v1['goods_price'],
                                'goods_number'    => $v1['goods_number'],
                                'total'           => $total,
                                'add_time'        => $time,
                            );
                        }
                    }
                }
            }

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();
                //设置excel属性基本信息
                $excel->getProperties()->setCreator("YUEASHOP")
                    ->setLastModifiedBy("YUEASHOP")
                    ->setTitle("YUEASHOP")
                    ->setSubject("订单列表")
                    ->setDescription("")
                    ->setKeywords("订单列表")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("订单列表");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '商城订单列表');
                //填入表头副标题
                $excel->getActiveSheet()->setCellValue('A2', '导出日期：' . date("Y-m-d H:i:s"));
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:P1');
                $excel->getActiveSheet()->mergeCells('A2:P2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:P3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P');
                $tableheader = array('订单号', '商品金额', '发货状态', '付款状态', '收货人', '联系电话', '收货地址', ' 快递单号', ' 快递费用', ' 快递公司', '商品名称', '商品编号', '商品单价', '购买数量', '单款合计', '创建时间');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }
                $i   = $excel_H;
                $num = 0;
                foreach ($orderData as $v) {
                    $excel_H = $excel_H + $num;
                    $num     = 0;
                    foreach ($v as $v1) {
                        $excel->getActiveSheet()->setCellValue('K' . $i, $v1['goods_name']);
                        $excel->getActiveSheet()->setCellValue('L' . $i, $v1['goods_sn']);
                        $excel->getActiveSheet()->setCellValue('M' . $i, $v1['goods_price']);
                        $excel->getActiveSheet()->setCellValue('N' . $i, $v1['goods_number']);
                        $excel->getActiveSheet()->setCellValue('O' . $i, $v1['total']);
                        $i   = $i + 1;
                        $num = $num + 1;
                    }
                    for ($k = $excel_H; $k < ($excel_H + $num); $k++) {
                        $excel->getActiveSheet()->mergeCells('A' . $excel_H . ':A' . $k);
                        $excel->getActiveSheet()->mergeCells('B' . $excel_H . ':B' . $k);
                        $excel->getActiveSheet()->mergeCells('C' . $excel_H . ':C' . $k);
                        $excel->getActiveSheet()->mergeCells('D' . $excel_H . ':D' . $k);
                        $excel->getActiveSheet()->mergeCells('E' . $excel_H . ':E' . $k);
                        $excel->getActiveSheet()->mergeCells('F' . $excel_H . ':F' . $k);
                        $excel->getActiveSheet()->mergeCells('G' . $excel_H . ':G' . $k);
                        $excel->getActiveSheet()->mergeCells('H' . $excel_H . ':H' . $k);
                        $excel->getActiveSheet()->mergeCells('I' . $excel_H . ':I' . $k);
                        $excel->getActiveSheet()->mergeCells('J' . $excel_H . ':J' . $k);
                        $excel->getActiveSheet()->mergeCells('P' . $excel_H . ':P' . $k);
                    }
                    foreach ($v as $v1) {

                        $excel->getActiveSheet()->setCellValue('A' . ($excel_H), $v1['order_id']);
                        $excel->getActiveSheet()->setCellValue('B' . ($excel_H), $v1['goods_amount']);
                        $excel->getActiveSheet()->setCellValue('C' . ($excel_H), $v1['shipping_status']);
                        $excel->getActiveSheet()->setCellValue('D' . ($excel_H), $v1['pay_status']);
                        $excel->getActiveSheet()->setCellValue('E' . ($excel_H), $v1['consignee']);
                        $excel->getActiveSheet()->setCellValue('F' . ($excel_H), $v1['mobile']);
                        $excel->getActiveSheet()->setCellValue('G' . ($excel_H), $v1['address']);
                        $excel->getActiveSheet()->setCellValue('H' . ($excel_H), $v1['shipping_id']);
                        $excel->getActiveSheet()->setCellValue('I' . ($excel_H), $v1['shipping_fee']);
                        $excel->getActiveSheet()->setCellValue('J' . ($excel_H), $v1['shipping_name']);
                        $excel->getActiveSheet()->setCellValue('P' . ($excel_H), $v1['add_time']);
                    }
                }
                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:P' . $excel_H)->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:P' . $excel_H)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:P' . $excel_H)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="订单.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                RPHP_RR::nodata();
            }

        }
    }

    //导出全部订单
    public function all_export()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $this->display();
        }
    }

    //导出快递信息
    public function export_express()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $this->display();
        }
    }

    // 执行导出快递信息
    public function exportdo()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            if ($_POST['act'] == "express") {

                $data = $model->getExpressData($_POST);

                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel       = new PHPExcel();
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); //,'N'   快递费用
                $tableheader = array('订单号', '订单金额', '支付金额', '付款时间', '收货人', '联系电话', '详细地址', '发货人', '发货人电话', '发货人地址');
                $excel_H     = 2;
                $excel->getActiveSheet()->getColumnDimension("A")->setWidth(12);
                $excel->getActiveSheet()->getColumnDimension("B")->setWidth(12);
                $excel->getActiveSheet()->getColumnDimension("C")->setWidth(12);
                $excel->getActiveSheet()->getColumnDimension("D")->setWidth(22);
                $excel->getActiveSheet()->getColumnDimension("E")->setWidth(22);
                $excel->getActiveSheet()->getColumnDimension("F")->setWidth(22);
                $excel->getActiveSheet()->getColumnDimension("G")->setWidth(70);
                $excel->getActiveSheet()->getColumnDimension("H")->setWidth(22);
                $excel->getActiveSheet()->getColumnDimension("I")->setWidth(22);
                $excel->getActiveSheet()->getColumnDimension("J")->setWidth(70);

                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue($letter[$i] . "1", $tableheader[$i]);
                }
                if ($data['data']) {
                    foreach ($data['data'] as $k => $v) {

                        $address = stripcslashes($v['address']);

                        if ($v['county_id'] > 0 && $data['region'][$v['county_id']]) {
                            $address = $data['region'][$v['county_id']] . $address;
                        }

                        if ($v['city_id'] > 0 && $data['region'][$v['city_id']]) {
                            $address = $data['region'][$v['city_id']] . $address;
                        }

                        if ($v['province_id'] > 0 && $data['region'][$v['province_id']]) {
                            $address = $data['region'][$v['province_id']] . $address;
                        }

                        unset($sender);
                        // 处理发货人信息
                        if ($data['user'][$v['uid']]) {
                            if ($data['user'][$v['uid']]['member_gradeid'] < 5 && $data['profile'][$v['uid']]) {
                                $sender = $data['profile'][$v['uid']];
                            } elseif ($data['user'][$v['uid']]['member_gradeid'] == 5 && $data['profile'][$data['user'][$v['uid']]['praent_uid']]) {
                                $sender = $data['profile'][$data['user'][$v['uid']]['praent_uid']];
                            }
                        }

                        $line = $excel_H + $k;
                        $excel->getActiveSheet()->setCellValue('A' . $line, $v['order_id']);
                        $excel->getActiveSheet()->setCellValue('B' . $line, $v['order_amount']);
                        $excel->getActiveSheet()->setCellValue('C' . $line, $v['pay_fee']);
                        $excel->getActiveSheet()->setCellValue('D' . $line, date("Y-m-d H:i:s", $v['pay_time']));
                        $excel->getActiveSheet()->setCellValue('E' . $line, stripcslashes($v['consignee']));
                        $excel->getActiveSheet()->setCellValue('F' . $line, stripcslashes($v['mobile']));
                        $excel->getActiveSheet()->setCellValue('G' . $line, stripcslashes($address));

                        if ($sender) {
                            $send_address = stripcslashes($sender['address']);

                            if ($sender['county_id'] > 0 && $data['region'][$sender['county_id']]) {
                                $send_address = $data['region'][$sender['county_id']] . $send_address;
                            }

                            if ($sender['city_id'] > 0 && $data['region'][$sender['city_id']]) {
                                $send_address = $data['region'][$sender['city_id']] . $send_address;
                            }

                            if ($sender['province_id'] > 0 && $data['region'][$sender['province_id']]) {
                                $send_address = $data['region'][$sender['province_id']] . $send_address;
                            }

                            $excel->getActiveSheet()->setCellValue('H' . $line, stripcslashes($sender['realname']));
                            $excel->getActiveSheet()->setCellValue('I' . $line, stripcslashes($sender['mobile']));
                            $excel->getActiveSheet()->setCellValue('J' . $line, stripcslashes($send_address));
                        }
                    }
                }

                $title = strip_tags($this->c['para']['shipping_name'][$_POST['shipping_id']]) . '-' . $_POST['export_start_date'] . '至' . $_POST['export_end_date'] . '订单快递信息';
                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/vnd.ms-execl");
                header('Content-Disposition:attachment;filename="' . $title . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');

            }
        }
    }

    // 用于客户端读取订单并打印
    public function clientprint()
    {
        $m    = $this->model;
        $data = $m->getClientOrder($_GET);
        if ($data) {
            $data['code'] = 200;
        } else {
            $data['code'] = 404;
        }

        echo json_encode($data);
    }

    //获取物流信息
    public function courier()
    {
        $priv  = array($this->_pvprefix . "_sp");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $this->view->auth = $auth;
            if ($_GET['id']) {
                $courier = trim($_GET['id']);
            }
            if ($_GET['type']) {
                $type = $_GET['type'];
            }
            $data = $model->getCourier($courier, $type);

            $this->view->data = $data;
            $this->display();
        }

    }
}
